package rootkit

import "syscall"

// --------------------------- 统计信息 --------------------------- //
type StatInfo struct {
	Total 		int
	Errors 		int
}

// --------------------------- 文件mode值 --------------------------- //
const (
	/* Read, write, execute/search by owner */
	RWXUser = 0700		/* [XSI] RWX mask for owner */
	RUser = 0400		/* [XSI] R for owner */
	WUser = 0200		/* [XSI] W for owner */
	XUser = 0100		/* [XSI] X for owner */

	/* Read, write, execute/search by group */
	RWXGroup = 0070		/* [XSI] RWX mask for group */
	RGroup = 0040		/* [XSI] R for group */
	WGroup = 0020		/* [XSI] W for group */
	XGroup = 0010		/* [XSI] X for group */

	/* Read, write, execute/search by others */
	RWXOther = 0007		/* [XSI] RWX mask for other */
	ROther = 0004		/* [XSI] R for other */
	WOther = 0002		/* [XSI] W for other */
	XOther = 0001		/* [XSI] X for other */
)

// --------------------------- NFS文件相关的内容 --------------------------- //
type FileSystemType struct {
	Name 		string
	Type 		uint32
	Flag 		int
}

var NetworkFileSystems = []FileSystemType {
	{
		Name: "NFS",
		Type: 0x6969,
		Flag: 1,
	},
	{
		Name: "CIFS",
		Type: 0xFF534D42,
		Flag: 1,
	},
}
var SkipFileSystems = []FileSystemType {
	{
		Name: "BTRFS",
		Type: 0x9123683E,
		Flag: 1,
	},
}

func IsNFS(dirName string) (bool, error) {
	stfs := &syscall.Statfs_t{}
	if err := syscall.Statfs(dirName, stfs); err != nil {
		return false, err
	}

	for _, item := range NetworkFileSystems {
		if item.Type == stfs.Type {
			if item.Flag == 1 {
				return true, nil
			} else {
				return false, nil
			}
		}
	}

	return false, nil
}

func SkipNFS(dirName string) (bool, error) {
	stfs := &syscall.Statfs_t{}
	if err := syscall.Statfs(dirName, stfs); err != nil {
		return false, err
	}

	for _, item := range SkipFileSystems {
		if item.Type == stfs.Type {
			if item.Flag == 1 {
				return true, nil
			} else {
				return false, nil
			}
		}
	}

	return false, nil
}
